const fs = require('fs')
const path = require('path')
const archiver = require('archiver')

// 确保scripts目录存在
if (!fs.existsSync('scripts')) {
  fs.mkdirSync('scripts')
}

// 创建输出目录
const output = fs.createWriteStream(path.join(__dirname, '../dist.zip'))
const archive = archiver('zip', {
  zlib: { level: 9 }, // 设置压缩级别
})

output.on('close', () => {
  console.log(
    '打包完成，文件大小: ' +
      (archive.pointer() / 1024 / 1024).toFixed(2) +
      ' MB'
  )
})

archive.on('error', (err) => {
  throw err
})

// 管道连接
archive.pipe(output)

// 将dist文件夹添加到zip
archive.directory('dist/', false)

// 完成归档
archive.finalize()
